/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-03-21     huger       the first version
 */
#ifndef APPLICATIONS_FOC_FOC_H_
#define APPLICATIONS_FOC_FOC_H_

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#include "bsp\bsp.h"

#define PWM2_MODE 0
#define PWM1_MODE 1
#define TNOISE_NS 1550
#define TRISE_NS 1550
#define SAMPLING_TIME_NS              700
#define SAMPLING_TIME                 (uint16_t)(((uint16_t)(SAMPLING_TIME_NS) * 72uL)/1000uL)
#define TNOISE                        (uint16_t)((((uint16_t)(TNOISE_NS)) * 72uL)/1000uL)
#define TRISE                         (uint16_t)((((uint16_t)(TRISE_NS)) * 72uL)/1000uL)

#define TW_AFTER                      ((uint16_t)(((TNOISE_NS)*72uL)/1000ul))
#define TW_BEFORE                     (((uint16_t)(((((uint16_t)(SAMPLING_TIME_NS)))*72uL)/1000ul))+1)


typedef struct
{
    float_t Ia;
    float_t Ib;
    float_t Ic;
}CURRENT_ABC_DEF;

typedef struct
{
    float_t Ialpha;
    float_t Ibeta;
}CURRENT_ALPHA_BETA_DEF;

typedef struct
{
    float_t Valpha;
    float_t Vbeta;
}VOLTAGE_ALPHA_BETA_DEF;

typedef struct
{
    float_t Cos;
    float_t Sin;
}TRANSF_COS_SIN_DEF;

typedef struct
{
    float_t Id;
    float_t Iq;
}CURRENT_DQ_DEF;

typedef struct
{
    float_t Vd;
    float_t Vq;
}VOLTAGE_DQ_DEF;

extern CURRENT_ABC_DEF Current_Iabc;
extern CURRENT_ALPHA_BETA_DEF Current_Ialpha_beta;
extern VOLTAGE_ALPHA_BETA_DEF Voltage_Alpha_Beta;
extern TRANSF_COS_SIN_DEF Transf_Cos_Sin;
extern CURRENT_DQ_DEF Current_Idq;
extern VOLTAGE_DQ_DEF Voltage_DQ;

void Clarke_Transf(CURRENT_ABC_DEF Current_abc_temp,CURRENT_ALPHA_BETA_DEF* Current_alpha_beta_temp);
void Angle_To_Cos_Sin(float_t angle_temp,TRANSF_COS_SIN_DEF* cos_sin_temp);
void Park_Transf(CURRENT_ALPHA_BETA_DEF current_alpha_beta_temp,TRANSF_COS_SIN_DEF cos_sin_temp,CURRENT_DQ_DEF* current_dq_temp);
void Rev_Park_Transf(VOLTAGE_DQ_DEF v_dq_temp,TRANSF_COS_SIN_DEF cos_sin_temp,VOLTAGE_ALPHA_BETA_DEF* v_alpha_beta_temp);
void SVPWM_Calc(VOLTAGE_ALPHA_BETA_DEF v_alpha_beta_temp,float_t Udc_temp,float_t Tpwm_temp);



#ifdef __cplusplus
}
#endif /* __cplusplus */



#endif /* APPLICATIONS_FOC_FOC_H_ */
